#include "Complex.h"
#include <iostream>
void Complex::setreal(double real)
{
	this->real = real;
}

void Complex::setimag(double imag)
{
	this->imag = imag;
}

void Complex::display()
{
	std::cout << real << "+" << imag << "i" << std::endl;
}

double Complex::getreal()
{
	return this->real;
}

double Complex::getimag()
{
	return this->imag;
}

Complex Complex::operator+(Complex b) const
{
	return Complex(real + b.real, imag + b.imag);
}

Complex Complex::operator-(Complex b) const
{
	return Complex(real - b.real, imag - b.imag);
}

Complex Complex::operator*(Complex b) const
{
	return Complex(real * b.real + imag * b.imag, imag * b.real + real * b.imag);
}

Complex Complex::operator/(Complex b) const
{
	/*
	(real + imag*i) / (b.real + b.imag*i)
	(real + imag*i)*(b.real - b.imag*i) / (b.real*b.real+b.imag*b.imag)
	real*b.real+imag*b.imag+imag*i*b.real-real*b.imag*i
	*/
	return Complex((real * b.real + imag * b.imag) / (b.real * b.real + b.imag * b.imag),
		(imag * b.real - real * b.imag) / (b.real * b.real + b.imag * b.imag));
}
